export function int2Hex(num = 0) {
    if (num === 0) {
        return '0';
    }
    const HEXS = '0123456789abcdef';
    let hex;
    while (num) {
        hex = HEXS.charAt(num % 16) + hex;
        num = Math.floor(num / 16);
    }
    return hex;
}

export function hex2Int(hex = '') {
    if (typeof hex !== 'string' || hex === '') {
        return NaN;
    }
    const hexs = [...hex.toLowerCase()];
    let resInt = 0;
    for (let i = 0; i < hexs.length; i++) {
        const hv = hexs[i];
        let num = hv.charCodeAt() < 58 ? +hv : code - 97 + 10;
        resInt = resInt * 16 + num;
    }
    return resInt;
}

/**
 * 判断机型是否支持
 */
export function notSupport(models = [], cb, options = { showToast: true }) {
    return function () {
        const PDAModel = getApp().globalData.PDAModel;
        if (models.includes(PDAModel)) {
            options.showToast &&
                uni.showToast({
                    title: '机型不支持',
                    position: 'bottom'
                });
            return false;
        }

        if (typeof cb === 'function') {
            return cb();
        }

        return true;
    };
}
